var hide = {};

hide.sumValue = 1;

hide.init = function() {
  hide.selectColor($('#getHtml .no-1'), 1);
  hide.inputValue();
  hide.addElement();
  hide.selectDelete($('#getHtml .no-1'), 1);
};

hide.addElement = function() {         
  var $gHtml = $('#getHtml');          
  var tmpHTML = $('#add-element-temp').html();  
  $('#nBtn').on('click', function() {  
    // var num = $gHtml.find('.no').length + 1;
    hide.sumValue += 1;
    var tmpDOM = $('<div class="weui_cells_temp no no-'+ hide.sumValue +'"></div>') 
    
    tmpDOM.append(tmpHTML);            
    $gHtml.append(tmpDOM);             
    
    hide.selectColor($gHtml.find('.no-' + hide.sumValue), hide.sumValue);
    // hide.currentID = hide.sumValue; 
    $('#getHtml .no-' + hide.sumValue).find('.nub').html(hide.sumValue);
    hide.selectDelete($gHtml.find('.no-' + hide.sumValue), hide.sumValue);
    eventInit();
  });
};

hide.selectDelete = function(e,num) {         
  e.find('.delete').on('click', function() { 
	  var obj = $(this);
	  $.confirm("您确定要删除吗?", "确认删除?", function() {
		  obj.closest('.no').remove();
      }, function() {
      //取消操作
      });
  });
};

hide.selectColor = function(e, num) {   
  e.find('.select-color').on('click', function() {
    hide.currentID = num;            
    hide.toggle(true);
  });
};

hide.inputValue = function() {
  $('#div2').find('li').on('click', function() {
    hide.setValue($(this).text());
  });
};

hide.setValue = function(value) {
  $('#getHtml .no-' + hide.currentID).find('.select-color').val(value);
  hide.toggle(false);
  hide.currentID = '';
};

window.onload = function() {
  hide.init();
}

